home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / BOOTRCD.ZIP;1 / BOOTRCD.CPP next >
Encoding:
C/C++ Source or Header  |  1992-08-14  |  2.0 KB  |  70 lines

  1. /*  BOOTRCD.CPP  ...  List boot record, etc. */
  2.  
  3. //  Copyright 1992 by George H. Mealy
  4.  
  5. #include    "brecord.h"
  6. #include    <stdlib.h>
  7. #include    <stdio.h>
  8. #include    <string.h>
  9. #include    <dos.h>
  10. #include    <ctype.h>
  11.  
  12. extern int optind, opterr;
  13. extern char *optarg;
  14. int getopt(int argc, char *argv[], char *options);
  15.  
  16. #define fatal(a, b) {printf(a, b); exit(-1); }
  17.  
  18. brecord *bootrcd;
  19. int list = 0, show = 0, set = 0;
  20. char *serial = NULL;
  21.  
  22. void showserial(), setserial(), usage();
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26.     int ch;
  27.     opterr = 1;
  28.     while (ch = getopt(argc, argv, "bsS:"), ch != EOF)
  29.         switch(ch) {
  30.             case 'b':   list = 1; break;
  31.             case 'S':   set = 1;  serial = strdup(optarg);
  32.             case 's':   show = 1; break;
  33. bailout:    case '?':   usage();  return -1;
  34.         }
  35.     if (argc == 1) goto bailout;
  36.     if (*argv[optind]) bootrcd = new brecord(*argv[optind]);
  37.     if (! bootrcd) fatal("Bad drive letter\n", NULL);
  38.     if (list) bootrcd->listboot();
  39.     if (set)  setserial();
  40.     if (show) showserial();
  41.     if (! (list | show | set)) bootrcd->listboot();
  42.     return 0;
  43. }
  44.  
  45. void setserial()
  46. {
  47.     char *p = strchr(serial, '.');          // Separate major and minor parts
  48.     if (p) *p++ = '\0';
  49.     bootrcd->bserial = MK_FP(atoi(serial), p? atoi(p): 0);
  50.     abswrite(bootrcd->drive, 1, 0L, bootrcd->bjunk1); // Update the boot record
  51. }
  52.  
  53. void showserial()
  54. {
  55.     printf("Serial number is %u.%u\n", FP_SEG(bootrcd->bserial),
  56.             FP_OFF(bootrcd->bserial));
  57. }
  58.  
  59. void usage()
  60. {
  61.     puts(
  62. "\n    Copyright 1992, George H. Mealy\n"
  63. "    USAGE: BOOTDIR [-bsS] [<serial #>] <drive letter>\n"
  64. "    where:\n"
  65. "       -b                          Lists bootrecord content\n"
  66. "       -s                          Shows the volume serial number only\n"
  67. "       -S  <serial #n>             Sets the new serial number.  It must\n"
  68. "                                     be in the form nnnn.nnnn .\n");
  69. }
  70.